package com.hmall.controller;

import com.hdmall.business.common.common.ServerResponse;
import com.hmall.service.MsgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * PC消息推送
 */
@RestController
@RequestMapping("/msg/")
@CrossOrigin(origins = "http://localhost:8088", maxAge = 3600)
@Api(value = "PC消息推送API", description = "PC消息推送API说明-v2")
public class MsgPushPcController {
    @Autowired
    private MsgService msgService;

    //队列消息推送
    @GetMapping("directPcMsgPush")
    @ApiOperation(value = "队列PC消息推送")
    public ServerResponse directPcMsgPush(String userName, String type, String body, String title, String value, String isImport) throws IOException {

       return msgService.pcMsgDirectPush(userName,type,body,title,value,isImport);
    }

    //扫码消息推送
    @GetMapping("pcMsgLoginDirectPush")
    @ApiOperation(value = "扫码消息推送")
    public ServerResponse pcMsgScanDirectPush(String key,String body,String title,String value,String isImport){

       return msgService.pcMsgScanDirectPush(key,body,title,value,isImport);
    }

    //删除消息推送
    @GetMapping("deleteMsg")
    @ApiOperation(value = "删除队列")
    public ServerResponse deleteMsg(String key){

        return msgService.deleteMsg(key);
    }

    @GetMapping("deleteRoutingKey")
    @ApiOperation(value = "删除某个队列的路由")
    public ServerResponse deleteRoutingKey(String exchange, String routingKey){

        return msgService.deleteRoutingKey(exchange, routingKey);
    }


    //广播PC消息推送
    @GetMapping("publicPcMsgPush")
    @ApiOperation(value = "广播PC消息推送")
    public ServerResponse publicPcMsgPush(String type,String body,String title,String value,String isImport){

        return msgService.pcMsgPublicPush(type,body,title,value, isImport);
    }

    //运营服务的广播消息推送
    @GetMapping("publicPcMsgPushToManager")
    @ApiOperation(value = "运营服务的广播消息推送")
    public ServerResponse publicPcMsgPushToManager(String type,String body,String title,String value,String isImport){

       return msgService.pcMsgToManagerPush(type,body,title,value, isImport);
    }

    //查询消息 传入类型
    @GetMapping("msgPcSelect")
    @ApiOperation(value = "PC消息查询")
    public ServerResponse msgPcSelect(@RequestParam("pageNo")Integer pageNo, @RequestParam("pageSize")Integer pageSize,
                                      @RequestParam("username")String username, @RequestParam("isPublic")Integer isPublic){

        return msgService.selectPushMsg(pageNo,pageSize,username,isPublic);
    }

    //改变成已读
    @GetMapping("updateIsReadPushMsgById")
    @ApiOperation(value = "PC改变成已读")
    public ServerResponse updateIsReadPushMsgById(@RequestParam("isRead")Integer isRead, @RequestParam("messageId")Integer messageId){

        if(isRead==1){
            return msgService.updateIsReadPushMsgById(isRead,messageId);
        }
        return ServerResponse.createByErrorMessage("不能改成已读，参数不正确");
    }

    //取消一个消息
    @GetMapping("cancelPushMsgById")
    @ApiOperation(value = "PC取消一个消息")
    public ServerResponse cancelPushMsgById(@RequestParam("enable")Integer enable, @RequestParam("messageId")Integer messageId){

        return msgService.cancelPushMsgById(enable,messageId);
    }

}
